<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/12/20
  Time: 16:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/css/bootstrap.min.css">
    <link rel="stylesheet" href="/css/laypage.css">
    <script type="text/javascript" src="/js/jquery/jquery.min.js"></script>
    <script type="text/javascript" src="/js/laypage/laypage.js"></script>
    <script type="text/javascript" src="/js/layer/layer.js"></script>
    <script type="text/javascript" src="/js/vue/vue.min.js"></script>
    <script type="text/javascript" src="/js/jquery.validation/1.14.0/jquery.validate.min.js"></script>
    <style>
        input.error {
            border: 1px solid red;
        }
    </style>
</head>

<body>
<div class="container">
    <form id="addUserForm">
        <br/>
        <div class="form-group">
            <label for="username">用户名称：</label>
            <input type="text" class="form-control" id="username" name="username" placeholder="输入名称">
        </div>
        <div class="form-group">
            <label for="userage">用户密码：</label>
            <input type="text" class="form-control" id="userage" name="password" placeholder="输入密码">
        </div>
        <div class="form-group">
            <button type="button" id="saveBtn" class="btn btn-success">提交</button>
            <button type="button" id="cancelBtn" class="btn btn-default">取消</button>
        </div>
    </form>
</div>
</body>
</html>
<script>
    var addUser =function () {
        if(!check().form()){
            return;
        }

        $.ajax({
            type:'GET',
            dataType:'json',
            url:'/user/addUsers.do',
            data:{
                username:$("#username").val(),
                password:$("#userage").val()
            },
            success: function () {
                $("#cancelBtn").click();
            }

        });
    }
    $("#saveBtn").on("click", function () {
        addUser();
    });
    $("#cancelBtn").on("click", function () {
        var index = parent.layer.getFrameIndex(window.name);
        parent.getUserPageList();
        parent.layer.close(index);
    })
    function check() {
        return $("#addUserForm").validate({
            rules: {
                username: {
                    required: true
                },
                password: {
                    required: true
                }
            },
            messages: {
                username: {
                    required: ""
                },
                password: {
                    required: ""
                }
            }
        })
    }
</script>

